#ifndef IMAGE_CACHE_H_
#define IMAGE_CACHE_H_

#include <png.h>
#include "texture.h"
#include <string>
#include <map>
#include <tr1/memory>

class ICacheException: public std::exception{
	private:
		std::string message;

		virtual const char* what()const throw(){
			return message.c_str();
		}
	public:

		ICacheException(const std::string& error) : message(error){}
		virtual ~ICacheException()throw(){}
};

class ImageCache{
	public:
		typedef std::tr1::shared_ptr<Texture> TexturePtr;

	private:
		std::map<std::string,TexturePtr> cache;

		ImageCache(){}
		ImageCache(const ImageCache& ic){}
		void operator =(const ImageCache& ic){}

		TexturePtr loadTexture(const std::string& _path,const std::string& name);
		void abort(const std::string& msg,FILE* fp=NULL,png_structp* png_ptr=NULL,png_infop* png_info=NULL);
	public:
		TexturePtr load(const std::string& path,const std::string& name);
		void save(const std::string& path,const TexturePtr& texture);
		void free(TexturePtr& ptr);
		void clear();

		static ImageCache& instance(){
			static ImageCache inst;
			return inst;
		}
};

#endif /* IMAGE_CACHE_H_ */
